/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ManagedBeans;

import Beans.UserRole;
import dao.UserRoleDao;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

/**

 @author jtanguay
 */
@ManagedBean
@RequestScoped
public class UserRoleManager {

  //Attributs
  private UserRole userRole;

  public UserRoleManager() {
  }

  //Getter and setter
  public UserRole getUserRole() {
    return userRole;
  }

  public void setUserRole(UserRole userRole) {
    this.userRole = userRole;
  }

  @PostConstruct
  public void init() {
    userRole = new UserRole();
  }

  //Recuperer tour les role d'un user
  public static List<UserRole> getAllRole(int idUser) {
    List<UserRole> userRoleList = UserRoleDao.getRoleForUser(idUser);

    return userRoleList;
  }

  //Upgrade d'un user
  public static void upgradeUserRole(int idRole, int idUser, int idRoleToUpgrade) {
    int upgrade = UserRoleDao.upgradeUserAccount(idRole, idUser, idRoleToUpgrade);
  }

}
